package com.wsd.smartcarwasher.controller;


import com.wsd.smartcarwasher.annotation.Log;
import com.wsd.smartcarwasher.domain.UserInfo;
import com.wsd.smartcarwasher.service.RedisService;
import com.wsd.smartcarwasher.service.UserInfoService;
import com.wsd.smartcarwasher.util.ReturnUtil;
import com.wsd.smartcarwasher.util.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Api(
        tags = {"PC-用户管理"}
)
@Controller
@CrossOrigin
public class UserInfoController {

    @Resource
    private UserInfoService userInfoService;



    @ApiOperation(
            value = "PC端－获取所有用户 ",
            notes = "PC端－获取帮助内容",
            produces = "application/json",
            response = UserInfo.class
    )
    @ApiImplicitParams({
            @ApiImplicitParam(  name = "mobile", value = "187029999212", required = false,  dataType = "String"),
    })
    @RequestMapping(
            value = {"/v1/getUserInfo"},
            method = {RequestMethod.GET},
            produces = {"application/json; charset=utf-8"}
    )
    @ResponseBody
    public ModelMap getAllUserInfo(@RequestParam int Page, @RequestParam int PageSize, HttpServletRequest request) {
        String mobile = request.getParameter("mobile");
        return  ReturnUtil.Success("获取所有用户成功",this.userInfoService.getAllUserInfo(Page,PageSize,mobile));
    }


    @Log("修改了用户的状态")
    @ApiOperation(
            value = "PC端－修改用户状态 ",
            notes = "PC端－修改用户状态",
            produces = "application/json",
            response = UserInfo.class
    )
    @ApiImplicitParams({
            @ApiImplicitParam(  name = "userId", value = "userId", required = true,  dataType = "String"),
            @ApiImplicitParam(  name = "state", value = "0 启用 1 禁用 ", required = true,  dataType = "Integer"),
    })
    @RequestMapping(
            value = {"/v1/updateUserStatus"},
            method = {RequestMethod.GET},
            produces = {"application/json; charset=utf-8"}
    )
    @ResponseBody
    public ModelMap getAllUserInfo(@RequestParam String userId, @RequestParam int state) {
        //String mobile = request.getParameter("mobile");
        UserInfo userInfo = new UserInfo();
        userInfo.setState(state);
        userInfo.setUserId(userId);
        int rows = this.userInfoService.updateUser(userInfo);
        if(rows>0){
            return  ReturnUtil.Success("修改用户状态成功");
        }
        return  ReturnUtil.Success("修改用户状态失败");
    }

}
